
using HDLogCenter.Dal.Repos;
using HDLogCenter.Infrastructure.ExternalServices;
using HDLogCenter.Infrastructure.Models;
using HDLogCenter.Infrastructure.Models.Inputs;
using Meilisearch;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace HDLogCenter.Bll.Services
{
    public class LogService
    {
        private readonly MeiliSearchService _meiliSearchService;

        public LogService( MeiliSearchService meiliSearchService)
        {
            _meiliSearchService = meiliSearchService;
        }

        public async Task<IEnumerable<LogDto>> GetAllLogsAsync()
        {
            var searchResult = await _meiliSearchService.SearchLogsAsync(
                new SearchLogsInput { PageIndex=1,PageSize=20 });
            
            return searchResult.Hits;
        }

        public async Task<LogDto> GetLogByIdAsync(long id)
        {
            return await _meiliSearchService.GetLogByIdAsync(id.ToString());
        }

        public async Task<SearchResult<LogDto>> SearchLogsAsync(SearchLogsInput input)
        {
            return await _meiliSearchService.SearchLogsAsync(input);
        }

        public async Task<int> GetLogCountAsync(SearchLogsInput input)
        {
            return  await _meiliSearchService.GetLogsCountAsync(input);
        }

        //public async Task<bool> UpdateLogAsync(LogDto logMessage)
        //{
        //    return await _meiliSearchService.UpdateLogAsync(logMessage);
        //}
    }
}
